package com.xiaoshuidi.cloud.module.iot.dal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbDoorlockPassword;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Carl
 * create 2019/09/16
 * email Carl.Sun@ixiaoshuidi.com
 **/

@Mapper
public interface TbDoorLockPasswordMapper extends BaseMapper<TbDoorlockPassword> {

    /**
     * 根据设备编号查找密码列表
     *
     * @return
     */
    @Select("SELECT t.*  " +
            "        FROM tb_doorlock_password t  " +
            "        WHERE t.device_no=#{deviceNo}  " +
            "        ORDER BY t.create_time DESC")
    List<TbDoorlockPassword> findDoorLockPasswordByDeviceNo(@Param("deviceNo") String deviceNo);

    /**
     * 根据门锁编号和模糊匹配密码ID查找密码
     *
     * @param deviceNo
     * @param thirdPasswrodId
     * @return
     */
    @Select("SELECT t.device_no,t.third_password_id  " +
            "        FROM tb_doorlock_password t  " +
            "        WHERE t.device_no =#{deviceNo}  " +
            "        AND t.third_password_id LIKE concat(#{thirdPasswrodId},'%')")
    TbDoorlockPassword getDoorLockPasswordByDeviceNo(@Param("deviceNo") String deviceNo, @Param("thirdPasswrodId") String thirdPasswrodId);

}
